<template>
  <div>
    <UploadExcel :on-success="onSuccess"></UploadExcel>
  </div>
</template>

<script>
import { addBatchEmployee } from '@/api/employees.js'
export default {
  name: 'ImportPage',
  components: {},
  data() {
    return {
    }
  },
  computed: {},
  watch: {},
  methods: {
    async onSuccess({ header, results }) {
      console.log(header, results)
      const map = {
        '手机号': 'mobile',
        '姓名': 'username',
        '入职日期': 'timeOfEntry',
        '转正日期': 'correctionTime',
        '工号': 'workNumber'
      }
      const data = results.map(t => {
        const item = {}
        for (const key in t) {
          const newKey = map[key]
          item[newKey] = t[key]
        }
        return item
      })
      console.log(data)
      await addBatchEmployee(data)
      this.$message.success('操作成功')
    }
  }
}
</script>
<style lang="less" scoped>
</style>
